package testcase;

import com.sun.deploy.net.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.testng.annotations.Test;
//import until.SignatureUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.*;

import static until.Sign.getSign;

public class OppoHttpClientGet {
    @Test
    public void testName() throws IOException {
        HttpPost post = new HttpPost("http://116.204.7.166:8018/v1/c2s/device/rename");
//        //用来执行get方法的
        DefaultHttpClient client = new DefaultHttpClient();
        //利用map集合添加header
//        Map<String,String> headers=new HashMap<String, String>();
//        headers.put("appId","com.oppo.ohome");
//        headers.put("timestamp",String.valueOf(System.currentTimeMillis()));
//        headers.put("token","TOKEN_hagP1+PNns3R0UOa4DNPgsy8f7Hknf+fNveHdBb9CCTfNKX4dJJeWEMqy+huprqU");
//      //  headers.put("imei", UUID.randomUUID().toString().replaceAll("-", ""));
//        for(String key:headers.keySet()){
//            String value=headers.get(key);
//            post.addHeader(key,value);
//        }
        post.addHeader("appId", "com.oppo.ohome");
        post.addHeader("timestamp", String.valueOf(System.currentTimeMillis()));
        post.addHeader("signature", "dyLBvfycxh5UQ_YMvMD8S9vB0wbpK9ZGGMrrci7pVRs");
        post.addHeader("token", "TOKEN_hagP1+PNns3R0UOa4DNPgsy8f7Hknf+fNveHdBb9CCTfNKX4dJJeWEMqy+huprqU");
        //post.addHeader("nonce","");

        //添加除了json格式以外的任何参数
        List<NameValuePair> param = new LinkedList<NameValuePair>();
        BasicNameValuePair param1 = new BasicNameValuePair("deviceId", "1099511823961");
        BasicNameValuePair param2 = new BasicNameValuePair("name", "23");
        param.add(param1);
        param.add(param2);
        // 使用URL实体转换工具
        UrlEncodedFormEntity entityParam = new UrlEncodedFormEntity(param, "UTF-8");
        post.setEntity(entityParam);

        HttpResponse response = client.execute(post);
        String result = EntityUtils.toString(response.getEntity());
        System.out.println(result);
    }

}
